package com.kira.scaffoldmvc.Job;

import com.kira.scaffoldmvc.Mapper.BookMapper;
import com.kira.scaffoldmvc.Mapper.UserMapper;
import com.kira.scaffoldmvc.POJO.RentBook;
import com.kira.scaffoldmvc.Service.BookService;
import com.kira.scaffoldmvc.Service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Slf4j
@Component()
public class BanJob {


@Autowired
private UserMapper userMapper;

@Autowired
private BookMapper bookMapper;


    @Scheduled(cron = "0 0 0 * * ?")
    public void ban(){
log.info("开始定时任务检查，自动设置黑名单");
HashMap map=new HashMap();
      List<RentBook> check = bookMapper.check();//查找所有没归还的书
        for(RentBook rb:check)
        {
            if(map.get(rb.getUserId())==null){
            map.put(rb.getUserId(),1);

            userMapper.lock(rb.getUserId());

            }
            else {
               //说明userId重复了
            }
        }








    }



}
